package util
{
	import flash.display.DisplayObject;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;

	/**
	 * 定义游戏的文本文字的各种样式。
	 * @author luguobin
	 */
	public class TextStyle
	{
		public function TextStyle()
		{
		}

		private static var _myTextFormat:TextFormat = new TextFormat("tahoma");

		/**设置文字的文本格式**/
		public static function getTextFormat(color:uint = 0xFFFFFF, size:int = 12, bold:Boolean = false, align:String = "left"):TextFormat
		{
			_myTextFormat.color = color;
			_myTextFormat.size = size;
			_myTextFormat.bold = bold;
			_myTextFormat.align = align;
			_myTextFormat.leading = 4;
			return _myTextFormat;
		}

		private static var _buttonGlowFilter:GlowFilter = new GlowFilter(0x000000, 1, 4, 4, 10, BitmapFilterQuality.LOW);

		/**按钮上文本边框颜色，默认值为：0x1f1200**/
		public static function getButtonTextFilter(color:uint = 0x1f1200):GlowFilter
		{
			_buttonGlowFilter.color = color;
			return _buttonGlowFilter;
		}

		/**默认的字体描边**/
		public static var fontBorderColor:uint = 0x1f1200;

		private static var _glowFilter:GlowFilter = new GlowFilter(0x000000, 1, 2, 2, 10, BitmapFilterQuality.LOW);

		/**添加文本边框颜色**/
		public static function addTextFrame(target:TextField, color:uint = 0xFFFFFF):void
		{
			var gfilter:GlowFilter;

			if(target)
			{
				var curFilters:Array = target.filters;

				for(var i:int = 0; i < curFilters.length; i++)
				{
					if(curFilters[i] is GlowFilter)
					{
						gfilter = curFilters[i];
						break;
					}
				}

				if(gfilter)
				{
					gfilter.color = color;
				}
				else
				{
					_glowFilter.color = color;
					gfilter = _glowFilter;
					curFilters.push(gfilter);
				}
				target.filters = curFilters;
			}
		}
	}
}